import {
  defineStore
} from "pinia"

import {
  ref
} from "vue"

export const useloginStore = defineStore('login', function() {

  const token = ref('')
  const userId = ref('')
  const refreshToken = ref('')


  // 跳转页面
  const redictUrl = ref('/pages/index/index')
  const openType = ref("switchTab")


  return {
    token,
    refreshToken,
    redictUrl,
    openType,
    userId
  }
}, {
  persist: {
    paths: ['token', 'refreshToken', 'openType', 'redictUrl', 'userId'],
    // #ifdef MP-WEIXIN
    storage: {
      // 小程序中可以使用 wx.setStorageSync 和 wx.getStorageSync
      setItem: (key, value) => wx.setStorageSync(key, value),
      getItem: (key) => wx.getStorageSync(key),
      removeItem: (key) => wx.removeStorageSync(key),
    },
    // #endif
  }
})